<?php

require_once PHP_UI_PATH . DS . 'UIControl.php';

class Contract extends UIControl {

    protected function getControlRendering() {
        $render = "
            <div style='width:400px; height:200px; overflow:scroll;'>
                {$this->getValue()}
            </div>
            <span>
                <input type='checkbox' value='si' id='_{$this->getId()}' class='contract validate-contract' />
                <label for='_{$this->getId()}'>Acepto</label>
            </span>
            ";
        return $render;
    }

    protected function getScriptRendering() {
        $render = "
           $('input:submit').attr('disabled', 'disabled');
           $('.contract').attr('checked', '');
           
           function check_contract(){
                $.each($('.contract'), function (index, value){
                    if(value.checked){
                        $('input:submit').removeAttr('disabled');
                    }else {
                        $('input:submit').attr('disabled', 'disabled');
                        return;
                    }
                });
           }

           $('.contract').change(check_contract);
           $('.contract').click(check_contract);
            ";
        return $render;
    }

}

?>
